﻿using System.Windows.Forms;
using Microsoft.Xna.Framework;

namespace Map_Creator.RedoUndo.Actions
{
    class AddMapAction:IAction
    {
        private Point size;
        private int tileSize;
        private string name;
        private MapInfo.Map map;
        private TreeView tree;
        private int mapID = 0;

        public AddMapAction(Point size, int tileSize, string name, TreeView tree)
        {
            this.size = size;
            this.tileSize = tileSize;
            this.name = name;
            this.tree = tree;
        }

        public void Do()
        {
            map = new MapInfo.Map(size, tileSize, mapID) { Name = name };
            mapID = map.ID;
            var mapNode = new ExtendedTreeNode(name, NodeType.Map, map);
            map.Node = mapNode;

            mapNode.ImageIndex = 0;

            tree.Nodes.Add(mapNode);

            MapInfo.Map.SelectedMap = map;
        }

        public void Undo()
        {
            map.Delete();
        }

        public string GetDescription()
        {
            return "Adds a Map Named " + name + " and Sized:" + size.X + ", " + size.Y;
        }

        public string GetName()
        {
            return "Add Map";
        }
    }
}
